#pragma once

class M2Model : public ModelBase
{
	M2FileHeader m_header;
	Mesh* m_meshes;
	ui32 m_nMeshes;
	std::string m_fileName;
	std::string m_modelName;
	Texture** m_textures;
	float translation[3];
	float scaling[3];
	float rotation[3];
	void LoadCached(M2ModelCache* c);
	bool m_selected;

	ADTModel* m_pSpawnMap;
	ui32 m_spawnEntry;

	D3DXVECTOR3 m_boundingBox[16];

	D3DXVECTOR3 m_selCircle[500];
	D3DXVECTOR3 m_selCircle2[500];
public:
	M2Model(std::string szFile, ADTModel* pMap, ui32 spawn);
	bool Init(bool noCache = false);
	void Draw(Vertex3F pos, Vertex3F tar);

	void SetSelected(bool selected) { m_selected = selected; }

	void SetRotation(float x, float y, float z)
	{
		rotation[0] = x;
		rotation[1] = y;
		rotation[2] = z;
	}

	void SetTranslation(float x, float y, float z)
	{
		translation[0] = x;
		translation[1] = y;
		translation[2] = z;
	}

	const M2FileHeader& GetHeader() { return m_header; }

	void ModTranslation(float x, float y, float z);
	

	bool Intersect(Vertex2F& mouse, float* pOut);

	void SetScale(float x, float y, float z)
	{
		scaling[0] = x;
		scaling[1] = y;
		scaling[2] = z;
	}

	void Deinit()
	{
		if(!m_error)
		{
			if(m_nMeshes)
				delete [] m_meshes;
			sM2Cache.RemoveCache(m_modelName);
		}
	}
	bool m_error;
};